package com.ebiz.jo.imageBrowser
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import org.fas.tween.FTween;
	
	public class ImageContainer
	{
		private var itemInfo:MainItem;
//		public var url:String;
		public var instance:Sprite;
		public var loader:ImageLoader = new ImageLoader();
//		public var btn:SimpleButton;
		public var tween:FTween = new FTween();
//		public var clue:String = '';
		public function ImageContainer(_instance:Sprite,_loadMovie1:MovieClip,_loadMovie2:MovieClip)
		{
			this.instance = _instance;
			//1
			var _imgBg:Sprite = (_instance.getChildByName('ciImageLoader1') as Sprite);
			this.instance.buttonMode = true;
			this.instance.addEventListener(MouseEvent.MOUSE_DOWN,loader_mouseDownHandler);
			loader.oriW = _imgBg.width;
			loader.oriH = _imgBg.height;
			loader.loadingMovie = _loadMovie1;
//			loader.loadURL("http://127.0.0.1/ebiz/resource/image/ico.jpg");
			_imgBg.addChild(loader);
			_loadMovie1.x = (_imgBg.x + _imgBg.width/2);
			
			_loadMovie1.y = (_imgBg.y + _imgBg.height/2);
			_instance.addChild(_loadMovie1);
			this.loadInfo(null);
		}
		private function loader_mouseDownHandler(event:MouseEvent):void{
			ImageBrowser.instance.showPop(this.itemInfo.id);
		}
		/*private function evtBtnRateMouseDown(_e:MouseEvent):void{
			if(this.url){
				flash.net.navigateToURL(new URLRequest(this.url),'_self');
			}
		}*/
		public function loadInfo(_itemInfo:MainItem):void{
			var _image:Sprite = this.instance;
			var _loader1:ImageLoader = this.loader;
//			var _btnRate:SimpleButton  = this.btn;
			var $oneLine:TextField = (_image.getChildByName('ciMsgOneLine') as TextField)
			var $twoLine1:TextField = (_image.getChildByName('ciMsgTwoLine1') as TextField)
			var $twoLine2:TextField = (_image.getChildByName('ciMsgTwoLine2') as TextField)
			if(!_itemInfo){
				$twoLine1.visible = false;
				$twoLine1.visible = false;
				$oneLine.visible = false;
				_loader1.unload();
				return;
			}
			if(this.itemInfo == _itemInfo){
				return;
			}
			this.itemInfo = _itemInfo;
//			this.clue = _itemInfo.msg_clue;
			//
			//			(_image.getChildByName('ciMsgBottom') as TextField).width = 360;
//			_t.defaultTextFormat = new TextFormat(null,null,null,true);
			
			var $msg1:String = String(_itemInfo.msg1);
			var $msg2:String = String(_itemInfo.msg2);
			if($msg2){
				$twoLine1.text = $msg1;
				$twoLine2.text = $msg2;
				$oneLine.visible = false;
				$twoLine1.visible = true;
				$twoLine2.visible = true;
			}else{
				$oneLine.text = $msg1;
				$oneLine.visible = true;
				$twoLine1.visible = false;
				$twoLine2.visible = false;
			}
			try{
				_loader1.load(new URLRequest(_itemInfo.image));
//				_loader1.loadURL("http://127.0.0.1/ebiz/resource/image/ico.jpg");
			}catch(_e:Error){
			}
//			this.url = _itemInfo.url.toString();
		}
	}
}